﻿using System;
using System.Collections.Generic;

namespace Vote
{
    enum ok
    {
        ok=1,
        nook=-1
    }
    /// <summary>
    /// 问题类:拥有ID、问题内容、创建时间、过期时间等属性。
    /// </summary>
    public class Question
    {
        public int IDQ { get; private set; }
        public string Content { get; private set; }
        DateTime DateNow;
        DateTime DateVoerDue;
        public List<QuestionOption> questionOptions = new List<QuestionOption>();
        public Question(int IDQ,string Content,DateTime DateVoerDue, List<QuestionOption> questionOptions)
        {
            this.IDQ = IDQ;
            this.Content = Content;
            QuestionOption.IDQOB = IDQ;
            this.DateNow = DateTime.Now;
            this.DateVoerDue = DateVoerDue;
            this.questionOptions = questionOptions;
        }
        /// <summary>
        /// 过期检测
        /// </summary>
        /// <returns></returns>
        public int PastDue()
        {
            if (DateTime.Compare(DateVoerDue , DateTime.Now)>0)
                return 1;
            else
                return -1;
        }
        public void AddQuestionOption(QuestionOption questionOption)
        {
            questionOptions.Add(questionOption);
        }

    }
    /// <summary>
    /// 问题选项：拥有ID、选项内容（文字、图片等）、票数等属性。
    /// </summary>
    public class QuestionOption
    {
        public static int IDQOB;
        public int IDQO { get; private set; }
        public string Content { get; private set; }
        public int poll { get; private set; }
        VoteParticulars voteParticulars=new VoteParticulars();
        public QuestionOption(int IDQ,string Content)
        {
            IDQOB = IDQ;
            IDQO = ++IDQOB;
            this.Content = Content;
        }
        public void Voting(User Voter)
        {
            if(this.voteParticulars.VotingParticulars(Voter)==1)
                this.poll++;
            
        }

    }
    /// <summary>
    /// 问题选项投票详情
    /// </summary>
    public class VoteParticulars
    {
        public  List<User> Users= new List<User>();
        public  List<DateTime> VoteTimes = new List<DateTime>();
        public int VotingParticulars(User Voter)
        {
            if (Users.Contains(Voter))
            {
                Console.WriteLine("此用户已经给它投过票了");
                return -1;
            }
            DateTime VotingTime = new DateTime();
            VotingTime = DateTime.Now;
            Users.Add(Voter);
            VoteTimes.Add(VotingTime);
            return 1;
        }

    }
    

}
